package com.wwz.controller;

import cn.hutool.db.PageResult;
import com.wwz.pojo.Room;
import com.wwz.pojo.RoomQuery;
import com.wwz.service.RoomService;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("test")
public class RoomController {
    @Resource
    private RoomService roomService;

    @GetMapping("get/{id}")
    public Room getOne(@PathVariable Integer id){
        return roomService.getOne(id);
    }

    @PostMapping("add")
    public Room add(@RequestBody Room room){
        return roomService.add(room);
    }

    @DeleteMapping("delete/{id}")
    public void delete(@PathVariable Integer id){
        roomService.delete(id);
    }

    @PostMapping("upData/{id}")
    public Room upData(@PathVariable Integer id ,
                       @RequestBody Room room) {
        return roomService.upData(id, room);
    }

    @GetMapping("list")
    public List<Room> list(){
       return roomService.findAll();
    }

    @GetMapping("toPage/{page}/{size}")
    public Page<Room> toPage(@PathVariable Integer page,
                             @PathVariable Integer size){
        return roomService.toPage(page-1, size);
    }

    @GetMapping("toPage2/{page}/{size}")
    public Page<Room> toPage2(@PathVariable Integer page,
                              @PathVariable Integer size,
                              @RequestBody RoomQuery query){
        return roomService.toPage2(page-1, size, query);
    }
}
